package com.taskcollection.control;

import com.alibaba.fastjson.JSONObject;
import com.taskcollection.bean.ProjectClassifyBean;
import com.taskcollection.bean.TeacherBean;
import com.taskcollection.service.ProjectClassifyService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created by haocongshun on 2016/8/18.
 */
public class ProjectClassifyControl {
    public void projectClassify(HttpServletRequest request, HttpServletResponse response) throws IOException {
        TeacherBean tea = (TeacherBean)request.getSession().getAttribute("教师");
        String Teacher_id = tea.getTeacher_id();
        String flag = request.getParameter("flag");
        ProjectClassifyService pcs = new ProjectClassifyService();
        String id = request.getParameter("id");
        String name = request.getParameter("name");
        JSONObject json = new JSONObject();
        System.out.println("***************flag="+flag);
        if(flag==null){
            List<ProjectClassifyBean> lpcb = pcs.getAll(Teacher_id);
            System.out.println("flag==null");
            json.put("getAll",lpcb);
        }else if("add".equals(flag)){
            System.out.println("add");
            json.put("msg",pcs.add(name,Teacher_id));
        }else if("delete".equals(flag)){
            System.out.println("delete");
            json.put("msg",pcs.delete(id));
        }else if("change".equals(flag)){
            System.out.println("***************change");
            json.put("msg",pcs.change(id,name));
        }
        System.out.println(json.toJSONString());
        response.getWriter().print(json.toJSONString());
    }
}
